package native

import "jvmgo/ch10/rtda"

type NativeMethod func(frame *rtda.Frame)

var registry = map[string]NativeMethod{}

func Register(className, methodName, methodDescriptor string, method NativeMethod) {
    //类名+方法名+方法描述符，三个信息唯一确定一个本地方法
    key := className + "~" + methodName + "~" + methodDescriptor
    registry[key] = method
}

//根据类名+方法名+方法描述符三个信息查找本地方法实现
func FindNativeMethod(className, methodName, methodDescriptor string) NativeMethod {
    key := className + "~" + methodName + "~" + methodDescriptor
    if method, ok := registry[key]; ok {
        return method
    }
    if methodDescriptor == "()V" && methodName == "registerNatives" {
        return emptyNativeMethod
    }
    return nil
}

func emptyNativeMethod(frame *rtda.Frame) {
    //空方法
}